<template>
    <form-bo-list-preview :key="key" ref="preview" :alias="alias" :pmtAlias="pmtAlias" :params="params"
                          :appId="queryAppId" @onRefresh="onRefresh"/>
</template>

<script type="text/ecmascript-6">
import FormBoListPreview from "@/views/modules/form/formBoList/FormBoListPreview";

export default {
    name: 'custom-list',
    components: {
        FormBoListPreview
    },
    data() {
        return {
            alias: '',
            pmtAlias: '',
            params: '',
            queryAppId: '',
            key: 0
        }
    },
    onShow() {
        uni.$on('onRefresh', (data) => {
            this.key++
        });
    },
    onLoad(option) {
        let params = JSON.parse(option.params)
        if(params.appId){
          uni.setStorage({key: "mobileAppId", data: params.appId})
        }
        this.init(params);
    },
    methods: {
        init(obj) {
            this.alias = obj.alias;
            this.pmtAlias = obj.pmtAlias;
            let params = {}
            if (obj.appId) {
                this.queryAppId = obj.appId;
                params['appId'] = obj.appId;
            }
            if (!obj.params) {
                obj.params = params
            } else {
                Object.assign(obj.params, params)
            }
            if (obj.params) {
                this.params = Object.keys(obj.params).map(function (key) {
                    return encodeURIComponent(key) + "=" + encodeURIComponent(obj.params[key]);
                }).join("&");
            }
        },
        onRefresh(){
            this.key++
        }
    }
}
</script>
